package rocky.mvcportlet.control;

import static org.junit.Assert.*;

import java.util.Map;

import net.sf.portletunit.PortletUnitActionRequest;
import net.sf.portletunit.PortletUnitRenderRequest;
import net.sf.portletunit.PortletUnitRenderResponse;

import org.junit.Test;

import rocky.mvcportlet.TestUserForm;
import rocky.portlet.MVCPortlet;

public class BaseControlTest {

//    @Test
//    public void testGetData() {
//        BaseControl control = new BaseControl();
//
//        PortletUnitActionRequest actionReq = new PortletUnitActionRequest();
//        actionReq.setParameter("firstName", "Thach");
//        actionReq.setParameter("lastName", "Lê");
//
//        TestUserForm formBean = (TestUserForm) control.getData(actionReq, TestUserForm.class);
//
//        assertEquals("Thach", formBean.getFirstName());
//        assertEquals("Lê", formBean.getLastName());
//
//    }

    @Test
    public void testGetMapData01() {
        BaseControl control = new BaseControl();

        PortletUnitActionRequest actionReq = new PortletUnitActionRequest();
        actionReq.setParameter("firstName", "Thach");
        actionReq.setParameter("lastName", "Lê");

        Map<String, Object> mapReq = (Map<String, Object>) control.getMapData(actionReq);

        assertEquals("Thach", (String) mapReq.get("firstName"));
        assertEquals("Lê", (String) mapReq.get("lastName"));

    }

    @Test
    public void testGetDataByMap() {
        BaseControl control = new BaseControl();

        PortletUnitActionRequest actionReq = new PortletUnitActionRequest();
        actionReq.setParameter("firstName", "Thach");
        actionReq.setParameter("lastName", "Lê");

        Map<String, Object> mapReq = (Map<String, Object>) control.getMapData(actionReq);
        
        assertEquals("Thach", (String) mapReq.get("firstName"));
        assertEquals("Lê", (String) mapReq.get("lastName"));

        TestUserForm formBean = (TestUserForm) control.getData(mapReq, TestUserForm.class);

        assertEquals("Thach", formBean.getFirstName());
        assertEquals("Lê", formBean.getLastName());
    }
}
